package org.nowcoder.huawei.c200;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

/**
 * 38 : 贪心歌手
 */
public class HC038 {
    static class City implements Comparable<City> {
        private int id;
        private int earnings;
        private int m;
        private int d;
        private int day; //在该城市待的天数

        public City(int id, int m, int d) {
            this.id = id;
            this.m = m;
            this.d = d;
            this.earnings = m;
            this.day = 0;
        }

        @Override
        public int compareTo(City o) {
            return o.earnings - this.earnings;
        }
    }

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] vars = br.readLine().split(" ");
            int t = Integer.parseInt(vars[0]); //天数
            int n = Integer.parseInt(vars[1]); //经过的城市数

            vars = br.readLine().split(" ");

            int total = 0; //城市之间需要的总时间
            for (int i = 0; i < vars.length; i++) {
                total += Integer.parseInt(vars[i]);
            }

            int count = 0;
            PriorityQueue<City> cities = new PriorityQueue<>(n);//途径过的所有城市
            while (count < n) {
                vars = br.readLine().split(" ");
                int m = Integer.parseInt(vars[0]);
                int d = Integer.parseInt(vars[1]);
                cities.add(new City(count++, m, d));
            }
            solve(cities, t - total);
        } catch (Exception ignore) {
        }
    }

    public static void solve(PriorityQueue<City> cities, int day) {
        int totalEarnings = 0;
        while (day > 0) {
            City city = cities.poll();
            totalEarnings += city.earnings;

            //更新当前城市收益
            city.day += 1;
            int var = city.m - city.d * city.day;
            city.earnings = Math.max(var, 0);
            cities.add(city);
            day--;
        }
        System.out.println(totalEarnings);
    }
}
